/*
 * @Author       : mark
 * @Date         : 2020-06-19
 * @copyleft Apache 2.0
 */ 

#ifndef SQLCONNRAII_H
#define SQLCONNRAII_H
#include "sqlconnpool.h"

/* 资源在对象构造初始化 资源在对象析构时释放*/
class SqlConnRAII {
public:
    SqlConnRAII(MYSQL** sql, SqlConnPool *connpool) {
        assert(connpool);
        conn_pool_ = connpool;
        sql_ = *sql = conn_pool_->GetConn();
    }
    
    ~SqlConnRAII() {
        conn_pool_->FreeConn(sql_);
    }
    
private:
    // std::shared_ptr<MYSQL> sql_;
    MYSQL *sql_;
    // std::shared_ptr<SqlConnPool> conn_pool_;
    SqlConnPool* conn_pool_;
};

#endif //SQLCONNRAII_H